package com.ruoyi.ma.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import com.ruoyi.ma.domain.vo.MaMaterialPlanDataDetailsReturnVo;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ma.domain.vo.MaMaterialPlanDetailsVo;
import com.ruoyi.ma.domain.bo.MaMaterialPlanDetailsBo;
import com.ruoyi.ma.service.IMaMaterialPlanDetailsService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料计划详情
 *
 * @author llb
 * @date 2024-11-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/ma/materialPlanDetails")
public class MaMaterialPlanDetailsController extends BaseController {

    private final IMaMaterialPlanDetailsService iMaMaterialPlanDetailsService;

    /**
     * 查询材料计划详情列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<MaMaterialPlanDetailsVo> list(MaMaterialPlanDetailsBo bo, PageQuery pageQuery) {
        return iMaMaterialPlanDetailsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出材料计划详情列表
     */
    @SaCheckLogin
    @Log(title = "材料计划详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MaMaterialPlanDetailsBo bo, HttpServletResponse response) {
        List<MaMaterialPlanDetailsVo> list = iMaMaterialPlanDetailsService.queryList(bo);
        ExcelUtil.exportExcel(list, "材料计划详情", MaMaterialPlanDetailsVo.class, response);
    }

    /**
     * 获取材料计划详情详细信息
     *
     * @param planDetailsId 主键
     */
    @SaCheckLogin
    @GetMapping("/{planDetailsId}")
    public R<MaMaterialPlanDetailsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long planDetailsId) {
        return R.ok(iMaMaterialPlanDetailsService.queryById(planDetailsId));
    }

    /**
     * 新增材料计划详情
     */
    @SaCheckLogin
    @Log(title = "材料计划详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MaMaterialPlanDetailsBo bo) {
        return toAjax(iMaMaterialPlanDetailsService.insertByBo(bo));
    }

    /**
     * 修改材料计划详情
     */
    @SaCheckLogin
    @Log(title = "材料计划详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MaMaterialPlanDetailsBo bo) {
        return toAjax(iMaMaterialPlanDetailsService.updateByBo(bo));
    }

    /**
     * 删除材料计划详情
     *
     * @param planDetailsIds 主键串
     */
    @SaCheckLogin
    @Log(title = "材料计划详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{planDetailsIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] planDetailsIds) {
        return toAjax(iMaMaterialPlanDetailsService.deleteWithValidByIds(Arrays.asList(planDetailsIds), true));
    }

    /**
     * 保存材料计划详情
     */
    @SaCheckLogin
    @Log(title = "保存材料计划详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/updateDetails")
    public R<Void> updateDetails(@Validated(AddGroup.class) @RequestBody MaMaterialPlanDataDetailsReturnVo bo) {
        return toAjax(iMaMaterialPlanDetailsService.updateDetails(bo));
    }

}
